#ifndef DIO_SYSCALL_FILE_H_
#define DIO_SYSCALL_FILE_H_
#include <fermat/dio/file_base.h>

namespace fermat {

class SyscallFile :public FileBase{
public:
	typedef FileBase::size_type size_type;
	typedef FileBase::offset_type offset_type;
public:
	SyscallFile(
		const std::string &filename,
		int mode,
		int queue_id = DEFAULT_QUEUE,
		unsigned int device_id = DEFAULT_DEVICE_ID );
	
	 RequestPtr aread(
		 void* buffer, offset_type offset, size_type bytes,
		 const CompletionHandler& on_cmpl = CompletionHandler());
	
	  RequestPtr awrite(
		 void* buffer, offset_type offset, size_type bytes,
		 const CompletionHandler& on_cmpl = CompletionHandler());
	
	  int serve(void* buffer, offset_type offset, size_type bytes,
						Request::ReadOrWriteType type);
	  void set_size(offset_type newsize);
	
	  offset_type size();
	

	
	  void lock();

	  void close();
	
	  void close_remove();
	
	  const char * io_type() const;
	  
	  int unlink();
	
	  int truncate( size_t length);

  	  int get_queue_id() const { return _queue_id; }
	
	  int get_allocator_id() const { return -1; }
	  
protected:
	  Mutex _fd_mutex; 
	  int _fd;   
	  int _mode;       
	  int _queue_id;
	  const std::string _path; 
	  bool _is_device;  
private:
	size_type _size();
	void      _set_size(size_t newsize);
	  
};


}
#endif

